from tortoise.exceptions import DoesNotExist
from models.base import Member

async def create_member(name: str, email: str) -> Member:
    return await Member.create(name=name, email=email)

async def get_member(member_id: int) -> Member | None:
    try:
        return await Member.get(id=member_id)
    except DoesNotExist:
        return None

async def update_member(member_id: int, name: str) -> Member | None:
    member = await Member.get_or_none(id=member_id)
    if member:
        member.name = name
        await member.save()
    return member

async def delete_member(member_id: int) -> bool:
    deleted_count = await Member.filter(id=member_id).delete()
    return deleted_count > 0